package com.rede.didiok.user.web;

import java.util.List;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.rede.didiok.common.constant.conf.MessageConf;
import com.rede.didiok.common.constant.conf.SysConf;
import com.rede.didiok.common.dto.user.GeneralEditDto;
import com.rede.didiok.common.exception.exceptionType.UpdateException;
import com.rede.didiok.common.utils.R;
import com.rede.didiok.common.utils.ResultUtil;
import com.rede.didiok.user.entity.GeneralEditEntity;
import com.rede.didiok.user.service.GeneralEditService;



/**
 * 通用内容修改表
 *
 * @author Rede
 * @email didiok@foxmail.com
 * @date 2023-08-07 18:21:17
 */
@Slf4j
@RestController
@RequestMapping("user/feign/generalEdit")
public class GeneralEditController {
    @Autowired
    private GeneralEditService generalEditService;

    /**
     * 获取通用修改列表
     * @param generalEditDto
     * @return
     */
    @ApiOperation(value = "获取通用修改列表", notes = "获取通用修改列表", response = String.class)
    @PostMapping("/getGeneralEditList")
    public String getGeneralEditList(@RequestBody GeneralEditDto generalEditDto) {

        return ResultUtil.result(SysConf.SUCCESS, generalEditService.getGeneralEditList(generalEditDto));
    }


    @ApiOperation(value = "批量删除", notes = "批量删除", response = String.class)
    @PostMapping("/deleteBatch")
    public String deleteBatchGeneralEdit(@RequestBody List<GeneralEditDto> generalEditDtoList) {

        return generalEditService.deleteBatchGeneralEdit(generalEditDtoList);
    }

    @ApiOperation(value = "审核修改", notes = "审核修改", response = String.class)
    @PostMapping("/audit")
    public String audit(@RequestBody GeneralEditDto generalEditDto) {
        return generalEditService.auditGeneralEdit(generalEditDto);
    }

    /**
     * 根据uid查询通用修改信息
     * @param uid
     * @return
     */
    @GetMapping("/getById")
    R getGeneralEditById(@RequestParam("uid") String uid){
        return R.ok().setData(generalEditService.getById(uid));
    }

    /**
     * 修改通用修改记录
     * @param generalEditDto
     * @return
     */
    @PostMapping("/getById")
    R updateGeneralEditById(@RequestBody GeneralEditDto generalEditDto){
        if (null == generalEditDto) {
            throw new UpdateException(MessageConf.PARAM_INCORRECT);
        }
        GeneralEditEntity generalEditEntity = new GeneralEditEntity();
        BeanUtils.copyProperties(generalEditDto, generalEditEntity);
        return R.ok().setData(generalEditService.updateById(generalEditEntity));
    }
}
